/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

import java.awt.Image;
import java.util.List;
import java.util.Map;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

public class Grafico {

    public static Image crearBar(List<Map<String, Object>> data,String titulo,String x,String y,int ancho, int alto){
     
     
     DefaultCategoryDataset dataset = new DefaultCategoryDataset();
     
     for(Map item: data){
         dataset.addValue(Integer.parseInt(item.get(y).toString()),"" , item.get(x).toString());
     
     }
     
     JFreeChart chart =  ChartFactory.createBarChart3D(titulo, x, y, (CategoryDataset)dataset, PlotOrientation.VERTICAL, false, true, true);
    
    return chart.createBufferedImage(ancho, alto);
    
    }
     public static Image crearTorta(List<Map<String, Object>> data,String titulo,String x,String y,int ancho, int alto){
     
     
     DefaultPieDataset dataset = new DefaultPieDataset();
     
     for(Map item: data){
         dataset.setValue(item.get(y).toString() +" "+Integer.parseInt(item.get(x).toString()),Integer.parseInt(item.get(x).toString()));
     
     }
     
     JFreeChart chart =  ChartFactory.createPieChart3D(titulo, dataset,  true, true, false);
    
    return chart.createBufferedImage(ancho, alto);
    
    }
    
}
